# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from elasticsearch import Elasticsearch
from gushici.settings import ES_URL
from gushici.items import GushiciItem,BiqugeItem
class GushiciPipeline(object):
    def open_spider(self,spider):
        self.es = Elasticsearch(ES_URL,timeout=1000)
    def close_spider(self,spider):
        pass
    def process_item(self, item, spider):
        if isinstance(item,GushiciItem):
            index = 'index'
        elif isinstance(item,BiqugeItem):
            index = 'biqu'
        self.es.index(index=index,doc_type='text',body=dict(item))
        return item
